﻿<?php
require_once('interaccionBD.php');

class userManager {
	private $username;
	private $logueado;
	private $error;
	private $mensaje;
	
	public function __construct() {
		$this->username = null;
		$this->pass = null;
		$this->error = null;
		$this->logueado = false;
	}	
	function redirect($url) {
	header("Location: $url");
	die();
	}
	function isLoggedIn() {
		return $this->logueado;
	}
	
	function checkLogin() {
		if( isset($_POST['username']) && $_POST['username']!="" && isset($_POST['password']) && $_POST['password']!=""){
			$username = $_POST['username'];
			$pass = $_POST['password'];
			$this->logueado = validarUsuario($username, $pass);//$this->validateUser($username, $pass);
			if($this->logueado)
			{
				$this->username= $username;
			}
			else
			{	
				$this->username= null;
				$this->error = "Contraseña o Usuario incorrecto.";
			}		
		}
		else
		{	
			$this->username= null;
			$this->error = "Campo vacío.";
		}
	}
	function printError() {
		echo "$this->error";
	}	
	function printMensaje() {
		echo "$this->mensaje";
	}
	
	function setMensaje($m) {
		$this->mensaje =$m;
	}
	function printUserData() {
		if ($this->isLoggedIn()) {
			echo "<p class='userData' >HOLA ".$this->username." </p>";			
		}
	}
	public function logout() {
	session_start();
	session_destroy();
	}
}
?>